package com.wondersgroup.fjzlpt.console.controller.view.yljgxx;

import com.quick.framework.util.QuickPrincipalUtils;
import com.wondersgroup.fjzlpt.console.service.inter.yljgxx.YljgxxService;
import com.wondersgroup.fjzlpt.console.utils.ControllerCommonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;

@Controller
@RequestMapping("/yljgxx")
public class YljgxxController {

	@Autowired
	private YljgxxService yljgxxService;
	
	@RequestMapping("/index.html")
	public String index_yljgxx(HttpServletRequest request)
	{
		request.setAttribute("jgpzjrxx", ControllerCommonUtils.jgpzjrxx);
		return "yljgxx/index";
	}
	
	@RequestMapping("/manager.html")
	public String manager_yljgxx(HttpServletRequest request)
	{
		String xzqhdm = QuickPrincipalUtils.getXzqhdm(request);
		request.setAttribute("xzqhdm",xzqhdm);
		return "yljgxx/manager";
	}

	/**配置机构资源接入信息*/
	@RequestMapping("/configZyjr.html")
	public String configZyjr(HttpServletRequest request){
		return "yljgxx/configZyjr";
	}

	/**获取机构图片*/
	@RequestMapping("/receiveJgtp")
	public void receiveJgtp(HttpServletResponse response, @RequestParam("id") String id){
		response.reset();
		response.setContentType("application/x-msdownload;charset=UTF-8");
		OutputStream out = null;
		try{
			out = response.getOutputStream();
			byte[] content = yljgxxService.receiveImage(id);
			out.write(content);
		}
		catch (Exception e){
			e.printStackTrace();
		}
		finally{
			try {
				if(out != null){
					out.flush();
					out.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}
